﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Model;


namespace MsDAL
{
    public partial class Buy3a01DAL : Buy3a01Base
    {
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public SqlApp Modify(Model.Buy3a01 ord3a01)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Buy3a01 set ");
            strSql.Append("pdlistid=@pdlistid ,bordqty=@bordqty ,ordqty=@ordqty ,preqty=@preqty ,price=@price ,cess=@cess ,ordamt=@ordamt ,accamt=@accamt ");
            strSql.Append("where listid=@listid ");
            SqlParameter[] parameters = {
				new SqlParameter("@pdlistid", SqlDbType.NVarChar),
				new SqlParameter("@bordqty", SqlDbType.Decimal),
				new SqlParameter("@ordqty", SqlDbType.Decimal),
				new SqlParameter("@preqty", SqlDbType.Decimal),
				new SqlParameter("@price", SqlDbType.Decimal),
				new SqlParameter("@cess", SqlDbType.Decimal),
				new SqlParameter("@ordamt", SqlDbType.Decimal),
				new SqlParameter("@accamt", SqlDbType.Decimal),
				new SqlParameter("@listid", SqlDbType.Int)
				};
            parameters[0].Value = ord3a01.Pdlistid;
            parameters[1].Value = ord3a01.Bordqty;
            parameters[2].Value = ord3a01.Ordqty;
            parameters[3].Value = ord3a01.Preqty;
            parameters[4].Value = ord3a01.Price;
            parameters[5].Value = ord3a01.Cess;
            parameters[6].Value = ord3a01.Ordamt;
            parameters[7].Value = ord3a01.Accamt;
            parameters[8].Value = ord3a01.Listid;

            return new SqlApp(strSql.ToString(), new ArrayList(parameters), false, "数据保存失败！");
        }

        public SqlApp DoAdjust(string rowId, double adjQty, double ppqty, double adjAmt)
        {
            var sql = "update buy3a01 set adjqty = isnull(adjqty,0) + @adjqty, adjamt=isnull(adjamt, 0) + @adjamt, adjppqty=isnull(adjppqty, 0) + @adjppqty where listid =@listid";

            SqlParameter[] parameters = {
				new SqlParameter("@adjqty", SqlDbType.Decimal),
				new SqlParameter("@adjamt", SqlDbType.Decimal),
				new SqlParameter("@adjppqty", SqlDbType.Decimal),
				new SqlParameter("@listid", SqlDbType.Int)
				};
            parameters[0].Value = adjQty;
            parameters[1].Value = adjAmt;
            parameters[2].Value = ppqty;
            parameters[3].Value = Convert.ToInt32(rowId);

            return new SqlApp(sql, new ArrayList(parameters), false, "数据保存失败！");
        }
    }
}
